// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router';
import store from './store';
import axios from 'axios';

// 导入并挂载自己封装的axios请求;
import myAxios from "./methods/myAxios";
Vue.prototype.$myAxios = myAxios;
// 导入并挂载自己封装的提示
import notice from "./methods/notice";
Vue.prototype.$myNotice = notice;
// 导入并挂载自己封装的存储类
import Verification from "./methods/verification";
Vue.prototype.$myStorage = Verification;
// 导入并挂载自己封装socket
import * as socketApi from './methods/socket';
Vue.prototype.$socketApi = socketApi;


import ECharts from 'vue-echarts'
import 'echarts/lib/chart/line'

Vue.component('chart', ECharts);


import('../static/style/reset.css');
import Element from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueAMap from "vue-amap";
import VueAwesomeSwiper from "vue-awesome-swiper";
import "swiper/css/swiper.css";
import Es6Promise from "es6-promise";

Es6Promise.polyfill();
import 'babel-polyfill'
import {lazyAMapApiLoaderInstance} from 'vue-amap';
import {Dialog, Popup, ActionSheet, cell, Uploader, Area, Notify, SwipeCell, Button,ImagePreview,Rate,Toast,List,PullRefresh,Stepper,Loading,TreeSelect,Picker,Collapse, CollapseItem,Sticky,Switch} from 'vant';
Vue.use(Rate);
Vue.use(Switch);
Vue.use(Sticky);
Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(Picker);
Vue.use(TreeSelect);
Vue.use(Loading);
Vue.use(Stepper);
Vue.use(PullRefresh);
Vue.use(List);
Vue.use(SwipeCell);
Vue.use(ImagePreview);
Vue.use(Button);
Vue.use(Uploader);
Vue.use(cell);
Vue.use(Notify);
Vue.use(Area);
Vue.use(Popup);
Vue.use(Toast);
// 全局注册
Vue.use(Dialog);
Vue.use(ActionSheet);
Vue.use(VueAwesomeSwiper);
Vue.use(Element);
Vue.use(VueAMap);


Vue.prototype.$axios = axios;
Vue.config.productionTip = false;
VueAMap.initAMapApiLoader({
  key: 'd3703fe2df9afaa3bf18dca6d173b987',
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  uiVersion: '1.0.11', // ui库版本，不配置不加载,
  v: '1.4.4'
});


// lazyAMapApiLoaderInstance.load().then(() => {
//   // your code ...
//   this.map = new AMap.Map('amapContainer', {
//     center: new AMap.LngLat(121.59996, 31.197646)
//   });
// });

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
});
router.afterEach((to,from, next) => {
  // window.onload = function () { alert("open");console.log(6666)};
  // window.addEventListener("load", function () { alert("open");console.log(6666) });
  window.scrollTo(0,0)
});

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!sessionStorage.getItem("user") || sessionStorage.getItem("user") == 0) {
      next({ path: '/views/login/login' })
    } else {
      next()
    }
  } else {
    next() // 确保一定要调用 next()
  }
});
